Welcome to python!

2.16 容器中的常用函数

集合就是没有键值的字典,所以集合的元素不能重复。

listA=[6,21,34,253,53,645,757,57,58,68]

turtleA=(6,21,34,253,53,645,757,57,58,68,58,58,58)

dictA={"name":["张三","李四"],"年龄":[25,32],"sex":["男","女"]}

setA={321,73,42,4,3,355,35,46}

print(len(listA)) #获取长度

print(max(listA),min(listA))

print(sum(listA))


listA.sort(reverse=False) #降序排列

print(listA)

print(turtleA.count(58)) #统计58出现的个数

#通过值获取列表、元组的索引

print(turtleA.index(58)) #只能获取第一个值的索引

#字典获取值:

print(dictA.get("name"))

返回值:

10

757 6

1952

[6, 21, 34, 53, 57, 58, 68, 253, 645, 757]

4

8

['张三', '李四']